package cn.ibizlab.odoo.core.odoo_account.service.impl;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.math.BigInteger;
import java.util.Collection;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import cn.ibizlab.odoo.core.client.model.Iaccount_bank_statement_import_journal_creation;
import cn.ibizlab.odoo.core.odoo_account.domain.Account_bank_statement_import_journal_creation;
import cn.ibizlab.odoo.core.odoo_account.filter.Account_bank_statement_import_journal_creationSearchContext;
import cn.ibizlab.odoo.core.odoo_account.service.IAccount_bank_statement_import_journal_creationService;
import cn.ibizlab.odoo.util.SearchResult;
import cn.ibizlab.odoo.util.log.IBIZLog;

/**
 * 实体[在银行对账单导入创建日记账] 服务对象接口实现
 */
@Slf4j
@IBIZLog
@Service
public class Account_bank_statement_import_journal_creationServiceImpl implements IAccount_bank_statement_import_journal_creationService {

    @Autowired
    private cn.ibizlab.odoo.core.client.service.Iaccount_bank_statement_import_journal_creationClientService account_bank_statement_import_journal_creationClientService;

    @Override
    public boolean create(Account_bank_statement_import_journal_creation account_bank_statement_import_journal_creation) {
        boolean bOk = false ;
        Iaccount_bank_statement_import_journal_creation clientModel = this.convert2Model(account_bank_statement_import_journal_creation,null);
        account_bank_statement_import_journal_creationClientService.create(clientModel) ;
        this.convert2Domain(clientModel,account_bank_statement_import_journal_creation);
        bOk = true ;

        return bOk ;
    }

    @Override
    public boolean remove(Integer id) {
        boolean bOk = false ;
        Iaccount_bank_statement_import_journal_creation clientModel = account_bank_statement_import_journal_creationClientService.createModel();
        clientModel.setId(id);
        account_bank_statement_import_journal_creationClientService.remove(clientModel) ;
        bOk = true ;
        return bOk ;
    }

    @Override
    public void createBatch(List<Account_bank_statement_import_journal_creation> account_bank_statement_import_journal_creations, int batchSize) {

                        //account_bank_statement_import_journal_creationClientService.createBatch(account_bank_statement_import_journal_creations,batchSize) ;

    }

    @Override
    public boolean update(Account_bank_statement_import_journal_creation account_bank_statement_import_journal_creation) {
        boolean bOk = false ;
        Iaccount_bank_statement_import_journal_creation clientModel = this.convert2Model(account_bank_statement_import_journal_creation,null);
        account_bank_statement_import_journal_creationClientService.update(clientModel) ;
        this.convert2Domain(clientModel,account_bank_statement_import_journal_creation) ;
        bOk = true;
        return bOk ;
    }

    @Override
    public Account_bank_statement_import_journal_creation get(Integer id) {
        Iaccount_bank_statement_import_journal_creation clientModel = account_bank_statement_import_journal_creationClientService.createModel();
        clientModel.setId(id);
        account_bank_statement_import_journal_creationClientService.get(clientModel) ;
        return this.convert2Domain(clientModel,null);
    }

    @Override
    public Account_bank_statement_import_journal_creation get(Account_bank_statement_import_journal_creation account_bank_statement_import_journal_creation) {
        Account_bank_statement_import_journal_creation retaccount_bank_statement_import_journal_creation = this.get(account_bank_statement_import_journal_creation.getId()) ;
    	BeanCopier copier=BeanCopier.create(retaccount_bank_statement_import_journal_creation.getClass(), account_bank_statement_import_journal_creation.getClass(), false);
        copier.copy(retaccount_bank_statement_import_journal_creation, account_bank_statement_import_journal_creation, null);
        return account_bank_statement_import_journal_creation ;
    }

    @Override
    public void updateBatch(List<Account_bank_statement_import_journal_creation> account_bank_statement_import_journal_creations, int batchSize) {

        //account_bank_statement_import_journal_creationClientService.updateBatch(account_bank_statement_import_journal_creations,batchSize) ;

    }

    @Override
    public void removeBatch(Collection<? extends Serializable> idList, int batchSize) {

        //account_bank_statement_import_journal_creationClientService.removeBatch(account_bank_statement_import_journal_creations) ;

    }

    /**
     * 查询集合 默认查询
     */
    @Override
    public Page<Account_bank_statement_import_journal_creation> searchDefault(Account_bank_statement_import_journal_creationSearchContext context) {
        List<Account_bank_statement_import_journal_creation> list = new ArrayList<Account_bank_statement_import_journal_creation>();
        Page<cn.ibizlab.odoo.core.client.model.Iaccount_bank_statement_import_journal_creation> clientModelList = account_bank_statement_import_journal_creationClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iaccount_bank_statement_import_journal_creation clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Account_bank_statement_import_journal_creation>(list, context.getPageable(), clientModelList.getTotalElements());
    }


    /**
     * 根据日记账查询
     */
    @Override
    public Page<Account_bank_statement_import_journal_creation> selectByOdoo_journal(Integer id){
        Account_bank_statement_import_journal_creationSearchContext context = new Account_bank_statement_import_journal_creationSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Account_bank_statement_import_journal_creation> list = new ArrayList<Account_bank_statement_import_journal_creation>();
        Page<cn.ibizlab.odoo.core.client.model.Iaccount_bank_statement_import_journal_creation> clientModelList = account_bank_statement_import_journal_creationClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iaccount_bank_statement_import_journal_creation clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Account_bank_statement_import_journal_creation>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Account_bank_statement_import_journal_creation> selectByOdoo_create(Integer id){
        Account_bank_statement_import_journal_creationSearchContext context = new Account_bank_statement_import_journal_creationSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Account_bank_statement_import_journal_creation> list = new ArrayList<Account_bank_statement_import_journal_creation>();
        Page<cn.ibizlab.odoo.core.client.model.Iaccount_bank_statement_import_journal_creation> clientModelList = account_bank_statement_import_journal_creationClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iaccount_bank_statement_import_journal_creation clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Account_bank_statement_import_journal_creation>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Account_bank_statement_import_journal_creation> selectByOdoo_write(Integer id){
        Account_bank_statement_import_journal_creationSearchContext context = new Account_bank_statement_import_journal_creationSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Account_bank_statement_import_journal_creation> list = new ArrayList<Account_bank_statement_import_journal_creation>();
        Page<cn.ibizlab.odoo.core.client.model.Iaccount_bank_statement_import_journal_creation> clientModelList = account_bank_statement_import_journal_creationClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iaccount_bank_statement_import_journal_creation clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Account_bank_statement_import_journal_creation>(list, context.getPageable(), clientModelList.getTotalElements());

    }



    public Iaccount_bank_statement_import_journal_creation convert2Model(Account_bank_statement_import_journal_creation domain , Iaccount_bank_statement_import_journal_creation model) {
        if(domain == null)
            return model ;
        if(model==null){
            model = account_bank_statement_import_journal_creationClientService.createModel() ;
        }

         if(domain.getCreate_dateDirtyFlag())
            model.setCreate_date(domain.getCreate_date());
         if(domain.getOutbound_payment_method_idsDirtyFlag())
            model.setOutbound_payment_method_ids(domain.getOutbound_payment_method_ids());
         if(domain.getWrite_dateDirtyFlag())
            model.setWrite_date(domain.getWrite_date());
         if(domain.getDisplay_nameDirtyFlag())
            model.setDisplay_name(domain.getDisplay_name());
         if(domain.getType_control_idsDirtyFlag())
            model.setType_control_ids(domain.getType_control_ids());
         if(domain.getInbound_payment_method_idsDirtyFlag())
            model.setInbound_payment_method_ids(domain.getInbound_payment_method_ids());
         if(domain.getIdDirtyFlag())
            model.setId(domain.getId());
         if(domain.getAccount_control_idsDirtyFlag())
            model.setAccount_control_ids(domain.getAccount_control_ids());
         if(domain.get__last_updateDirtyFlag())
            model.set__last_update(domain.get__last_update());
         if(domain.getAlias_domainDirtyFlag())
            model.setAlias_domain(domain.getAlias_domain());
         if(domain.getRefund_sequence_idDirtyFlag())
            model.setRefund_sequence_id(domain.getRefund_sequence_id());
         if(domain.getSequenceDirtyFlag())
            model.setSequence(domain.getSequence());
         if(domain.getCurrency_idDirtyFlag())
            model.setCurrency_id(domain.getCurrency_id());
         if(domain.getBank_idDirtyFlag())
            model.setBank_id(domain.getBank_id());
         if(domain.getCreate_uid_textDirtyFlag())
            model.setCreate_uid_text(domain.getCreate_uid_text());
         if(domain.getLoss_account_idDirtyFlag())
            model.setLoss_account_id(domain.getLoss_account_id());
         if(domain.getDefault_credit_account_idDirtyFlag())
            model.setDefault_credit_account_id(domain.getDefault_credit_account_id());
         if(domain.getRefund_sequenceDirtyFlag())
            model.setRefund_sequence(domain.getRefund_sequence());
         if(domain.getAt_least_one_outboundDirtyFlag())
            model.setAt_least_one_outbound(domain.getAt_least_one_outbound());
         if(domain.getProfit_account_idDirtyFlag())
            model.setProfit_account_id(domain.getProfit_account_id());
         if(domain.getUpdate_postedDirtyFlag())
            model.setUpdate_posted(domain.getUpdate_posted());
         if(domain.getRefund_sequence_number_nextDirtyFlag())
            model.setRefund_sequence_number_next(domain.getRefund_sequence_number_next());
         if(domain.getAlias_idDirtyFlag())
            model.setAlias_id(domain.getAlias_id());
         if(domain.getCodeDirtyFlag())
            model.setCode(domain.getCode());
         if(domain.getGroup_invoice_linesDirtyFlag())
            model.setGroup_invoice_lines(domain.getGroup_invoice_lines());
         if(domain.getAlias_nameDirtyFlag())
            model.setAlias_name(domain.getAlias_name());
         if(domain.getBank_account_idDirtyFlag())
            model.setBank_account_id(domain.getBank_account_id());
         if(domain.getColorDirtyFlag())
            model.setColor(domain.getColor());
         if(domain.getAt_least_one_inboundDirtyFlag())
            model.setAt_least_one_inbound(domain.getAt_least_one_inbound());
         if(domain.getBank_acc_numberDirtyFlag())
            model.setBank_acc_number(domain.getBank_acc_number());
         if(domain.getSequence_number_nextDirtyFlag())
            model.setSequence_number_next(domain.getSequence_number_next());
         if(domain.getCompany_partner_idDirtyFlag())
            model.setCompany_partner_id(domain.getCompany_partner_id());
         if(domain.getCompany_idDirtyFlag())
            model.setCompany_id(domain.getCompany_id());
         if(domain.getWrite_uid_textDirtyFlag())
            model.setWrite_uid_text(domain.getWrite_uid_text());
         if(domain.getDefault_debit_account_idDirtyFlag())
            model.setDefault_debit_account_id(domain.getDefault_debit_account_id());
         if(domain.getActiveDirtyFlag())
            model.setActive(domain.getActive());
         if(domain.getBank_statements_sourceDirtyFlag())
            model.setBank_statements_source(domain.getBank_statements_source());
         if(domain.getKanban_dashboardDirtyFlag())
            model.setKanban_dashboard(domain.getKanban_dashboard());
         if(domain.getKanban_dashboard_graphDirtyFlag())
            model.setKanban_dashboard_graph(domain.getKanban_dashboard_graph());
         if(domain.getShow_on_dashboardDirtyFlag())
            model.setShow_on_dashboard(domain.getShow_on_dashboard());
         if(domain.getPost_at_bank_recDirtyFlag())
            model.setPost_at_bank_rec(domain.getPost_at_bank_rec());
         if(domain.getBelongs_to_companyDirtyFlag())
            model.setBelongs_to_company(domain.getBelongs_to_company());
         if(domain.getNameDirtyFlag())
            model.setName(domain.getName());
         if(domain.getTypeDirtyFlag())
            model.setType(domain.getType());
         if(domain.getSequence_idDirtyFlag())
            model.setSequence_id(domain.getSequence_id());
         if(domain.getCreate_uidDirtyFlag())
            model.setCreate_uid(domain.getCreate_uid());
         if(domain.getJournal_idDirtyFlag())
            model.setJournal_id(domain.getJournal_id());
         if(domain.getWrite_uidDirtyFlag())
            model.setWrite_uid(domain.getWrite_uid());
        return model ;
    }

    public Account_bank_statement_import_journal_creation convert2Domain( Iaccount_bank_statement_import_journal_creation model ,Account_bank_statement_import_journal_creation domain) {
        if(model == null)
            return domain ;
        if(domain == null){
            domain = new Account_bank_statement_import_journal_creation();
        }

        if(model.getCreate_dateDirtyFlag())
            domain.setCreate_date(model.getCreate_date());
        if(model.getOutbound_payment_method_idsDirtyFlag())
            domain.setOutbound_payment_method_ids(model.getOutbound_payment_method_ids());
        if(model.getWrite_dateDirtyFlag())
            domain.setWrite_date(model.getWrite_date());
        if(model.getDisplay_nameDirtyFlag())
            domain.setDisplay_name(model.getDisplay_name());
        if(model.getType_control_idsDirtyFlag())
            domain.setType_control_ids(model.getType_control_ids());
        if(model.getInbound_payment_method_idsDirtyFlag())
            domain.setInbound_payment_method_ids(model.getInbound_payment_method_ids());
        if(model.getIdDirtyFlag())
            domain.setId(model.getId());
        if(model.getAccount_control_idsDirtyFlag())
            domain.setAccount_control_ids(model.getAccount_control_ids());
        if(model.get__last_updateDirtyFlag())
            domain.set__last_update(model.get__last_update());
        if(model.getAlias_domainDirtyFlag())
            domain.setAlias_domain(model.getAlias_domain());
        if(model.getRefund_sequence_idDirtyFlag())
            domain.setRefund_sequence_id(model.getRefund_sequence_id());
        if(model.getSequenceDirtyFlag())
            domain.setSequence(model.getSequence());
        if(model.getCurrency_idDirtyFlag())
            domain.setCurrency_id(model.getCurrency_id());
        if(model.getBank_idDirtyFlag())
            domain.setBank_id(model.getBank_id());
        if(model.getCreate_uid_textDirtyFlag())
            domain.setCreate_uid_text(model.getCreate_uid_text());
        if(model.getLoss_account_idDirtyFlag())
            domain.setLoss_account_id(model.getLoss_account_id());
        if(model.getDefault_credit_account_idDirtyFlag())
            domain.setDefault_credit_account_id(model.getDefault_credit_account_id());
        if(model.getRefund_sequenceDirtyFlag())
            domain.setRefund_sequence(model.getRefund_sequence());
        if(model.getAt_least_one_outboundDirtyFlag())
            domain.setAt_least_one_outbound(model.getAt_least_one_outbound());
        if(model.getProfit_account_idDirtyFlag())
            domain.setProfit_account_id(model.getProfit_account_id());
        if(model.getUpdate_postedDirtyFlag())
            domain.setUpdate_posted(model.getUpdate_posted());
        if(model.getRefund_sequence_number_nextDirtyFlag())
            domain.setRefund_sequence_number_next(model.getRefund_sequence_number_next());
        if(model.getAlias_idDirtyFlag())
            domain.setAlias_id(model.getAlias_id());
        if(model.getCodeDirtyFlag())
            domain.setCode(model.getCode());
        if(model.getGroup_invoice_linesDirtyFlag())
            domain.setGroup_invoice_lines(model.getGroup_invoice_lines());
        if(model.getAlias_nameDirtyFlag())
            domain.setAlias_name(model.getAlias_name());
        if(model.getBank_account_idDirtyFlag())
            domain.setBank_account_id(model.getBank_account_id());
        if(model.getColorDirtyFlag())
            domain.setColor(model.getColor());
        if(model.getAt_least_one_inboundDirtyFlag())
            domain.setAt_least_one_inbound(model.getAt_least_one_inbound());
        if(model.getBank_acc_numberDirtyFlag())
            domain.setBank_acc_number(model.getBank_acc_number());
        if(model.getSequence_number_nextDirtyFlag())
            domain.setSequence_number_next(model.getSequence_number_next());
        if(model.getCompany_partner_idDirtyFlag())
            domain.setCompany_partner_id(model.getCompany_partner_id());
        if(model.getCompany_idDirtyFlag())
            domain.setCompany_id(model.getCompany_id());
        if(model.getWrite_uid_textDirtyFlag())
            domain.setWrite_uid_text(model.getWrite_uid_text());
        if(model.getDefault_debit_account_idDirtyFlag())
            domain.setDefault_debit_account_id(model.getDefault_debit_account_id());
        if(model.getActiveDirtyFlag())
            domain.setActive(model.getActive());
        if(model.getBank_statements_sourceDirtyFlag())
            domain.setBank_statements_source(model.getBank_statements_source());
        if(model.getKanban_dashboardDirtyFlag())
            domain.setKanban_dashboard(model.getKanban_dashboard());
        if(model.getKanban_dashboard_graphDirtyFlag())
            domain.setKanban_dashboard_graph(model.getKanban_dashboard_graph());
        if(model.getShow_on_dashboardDirtyFlag())
            domain.setShow_on_dashboard(model.getShow_on_dashboard());
        if(model.getPost_at_bank_recDirtyFlag())
            domain.setPost_at_bank_rec(model.getPost_at_bank_rec());
        if(model.getBelongs_to_companyDirtyFlag())
            domain.setBelongs_to_company(model.getBelongs_to_company());
        if(model.getNameDirtyFlag())
            domain.setName(model.getName());
        if(model.getTypeDirtyFlag())
            domain.setType(model.getType());
        if(model.getSequence_idDirtyFlag())
            domain.setSequence_id(model.getSequence_id());
        if(model.getCreate_uidDirtyFlag())
            domain.setCreate_uid(model.getCreate_uid());
        if(model.getJournal_idDirtyFlag())
            domain.setJournal_id(model.getJournal_id());
        if(model.getWrite_uidDirtyFlag())
            domain.setWrite_uid(model.getWrite_uid());
        return domain ;
    }


}
